import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import path from "path";
// https://vitejs.dev/config/
export default ({ mode }: any) => {
  console.log(mode, "mode");
  const env = loadEnv(mode, process.cwd());
  console.log(env, "env");
  return defineConfig({
    base:"/chat",
    plugins: [
      react(),
      createSvgIconsPlugin({
        // 指定要缓存的图标文件夹
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
        // 指定 symbolId 格式
        symbolId: "icon-[dir]-[name]",
        /**
         * 自定义插入位置
         * @default: body-last
         */
        inject: "body-first",
        customDomId: "__svg__icons__dom__"
      })
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
        "@assets": path.join(__dirname, "src/assets")
      }
    },
    server: {
      host: "localhost",
      port: 5174,
      open: true,
      proxy: {
        "/chatapi": {
          target: "http://localhost:3000",
          changeOrigin: true,
          rewrite: path => path.replace(/^\/chatapi/, "")
        }
      }
    }
  });
};
